package com.pi.reservaCita2.controler;

import java.sql.ResultSet;
import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.pi.reservaCita2.client.Getdata;
import com.pi.reservaCita2.client.GetdataAsync;

public class registerHandler extends Composite implements BlurHandler {

	
	private TextBox newDni;
	private TextBox newNombres;
	private TextBox newApellido1;
	private TextBox newApellido2;
	private ListBox newSexo;
	private TextBox newobservable;

	
	public registerHandler ()
	{
		newDni=new TextBox();
		newNombres= new TextBox();
		newApellido1=new TextBox();
		newApellido2 = new TextBox();
		newobservable= new TextBox();
		newSexo= new ListBox();
		newSexo.addItem("Masculino");
		newSexo.addItem("Femenino");
		
		
		newDni.addBlurHandler(this);
		newobservable.addBlurHandler(this);
		
		
	}
		
	
	public void onBlur(BlurEvent event) {
		// TODO Auto-generated method stub
		Widget sender = (Widget) event.getSource();
		GetdataAsync data= GWT.create(Getdata.class);
		if(sender== newDni)
		
		{
			if(data == null){ data = GWT.create(Getdata.class);}
			
			AsyncCallback<ArrayList<String[]> > callback = new AsyncCallback<ArrayList<String[]> >() {
										
				@Override
				public void onFailure(Throwable caught) {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void onSuccess(ArrayList<String[]> result) {
					// TODO Auto-generated method stub
					
					
					
					newDni.setText(result.get(0)[1]);
				}
			};
			
			data.getaDatadb("er", callback);
			
			//se tiene k pregntar a la base de datos 
		}
		if(sender == newobservable)
		{
			GetObservableAsync obs = GWT.create(Observable.class);
			if(obs==null)
			{obs = GWT.create(Observable.class);		
			}
			AsyncCallback<Observable > callback = new AsyncCallback<Observable> (){

				@Override
				public void onFailure(Throwable caught) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onSuccess(Observable result) {
					// TODO Auto-generated method stub
					
					//parent=result;
				}};

				obs.getaObss("",callback);
			
		}
		
		
		
	}


	public TextBox getNewDni() {
		return newDni;
	}


	public void setNewDni(TextBox newDni) {
		this.newDni = newDni;
	}


	public TextBox getNewNombres() {
		return newNombres;
	}


	public void setNewNombres(TextBox newNombres) {
		this.newNombres = newNombres;
	}


	public TextBox getNewApellido1() {
		return newApellido1;
	}


	public void setNewApellido1(TextBox newApellido1) {
		this.newApellido1 = newApellido1;
	}


	public TextBox getNewApellido2() {
		return newApellido2;
	}
	
	public TextBox getnewobservable()
	{
		
		return newobservable;
	}


	public void setNewApellido2(TextBox newApellido2) {
		this.newApellido2 = newApellido2;
	}


	public ListBox getNewSexo() {
		return newSexo;
	}


	public void setNewSexo(ListBox newSexo) {
		this.newSexo = newSexo;
	}
	

}
